const env = process.env.NODE_ENV || 'development'; // 默认为开发环境
function request(url, method = 'GET', data = {}, token) {
	return new Promise((resolve, reject) => {

		let token = uni.getStorageSync('wxwork_token');

		let header = {
			'Content-Type': 'application/json',
			'Authorization': token
		}


		uni.request({
			url: url,
			method: method,
			data: data,
			header: header,
			success: (res) => {
				// console.log(res, '------------')
				if (res.data.code == 0) {
					resolve(res.data);
				} else if (res.data.code == 401) {

					const encodedTarget = encodeURIComponent('/pages/index/callBack');
					const authUrl =
						`https://jinzhizixun.com.cn/wx/yingyong/login?wantUrl=${encodedTarget}`;
					console.log('authUrl', authUrl);
					// window.location.href = authUrl
					if (env === 'development') {
						console.log('当前是开发环境');
					} else if (env === 'production') {
						console.log('当前是生产环境');
						window.location.href = authUrl
					}

				} else {
					resolve(res.data);
				}

			},
			fail: (err) => {
				reject(err);
			}
		});
	});
}
export default request